package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.qo.JsonResult;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.ICustomerService;
import cn.wolfcode.crm.service.ICustomerTransferService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("customerTransfer")
@Controller
public class CustomerTransferController {

	@Autowired
	private ICustomerTransferService customerTransferService;

	@Autowired
	private ICustomerService customerService;
	
	@RequestMapping("list")
	public String list(Model model, @ModelAttribute("qo")QueryObject qo){
		//int i = 1/0;
		PageInfo<CustomerTransfer> pageInfo = customerTransferService.query(qo);
		model.addAttribute("pageInfo",pageInfo);
		return "customerTransfer/list";
	}
	

	

	@RequestMapping("save")
	@ResponseBody
	public JsonResult saveOrUpdate(CustomerTransfer customerTransfer){
		customerTransferService.insert(customerTransfer);
		return new JsonResult(true,"新增或修改成功");

	}
	@RequestMapping("yijiao")
	@ResponseBody
	public JsonResult yijiao(CustomerTransfer customerTransfer){
		customerTransferService.insert(customerTransfer);
		customerService.updateStatus(customerTransfer.getCustomer().getId(),0);
		customerService.updateSeller(customerTransfer.getCustomer().getId(),customerTransfer.getNewSeller().getId());
		return new JsonResult(true,"新增或修改成功");

	}
}
